import { Global, Module } from "@nestjs/common";
import { APP_GUARD } from "@nestjs/core";
import { JwtModule } from "@nestjs/jwt";
import { PassportModule } from "@nestjs/passport";

import { jwtConstants } from "./constants";
import { JwtAuthGuard } from "./guard/jwt-auth.guard";
import { RolesCheckGuard } from "./guard/role-check.guard";
import { UserTypeCheckGuard } from "./guard/user-type-check.guard";
import { JwtStrategy } from "./strategy/jwt.strategy";

@Global()
@Module({
    imports: [
        PassportModule,
        JwtModule.register({
            secret: jwtConstants.secret,
            signOptions: { expiresIn: jwtConstants.expiresIn }
        })
    ],
    providers: [
        // LocalStrategy,
        JwtStrategy,
        // LocalAuthGuard,
        // JwtAuthGuard
        {
            provide: APP_GUARD,
            useClass: JwtAuthGuard
        },
        {
            provide: APP_GUARD,
            useClass: RolesCheckGuard
        },
        {
            provide: APP_GUARD,
            useClass: UserTypeCheckGuard
        }
    ],
    exports: [JwtModule]
})
export class AuthModule {}
